package dao.impl;

import dao.StoreDAO;
import pojo.Store;
import service.StoreService;

import java.util.List;

/**
 * @author CaiKe
 * @create 2021/1/9
 */
public class StoreDAOImpl extends BaseDAO implements StoreDAO {

    @Override
    public Integer addStore(Store store) {
        String sql = "insert into t_store(ownerId, name, description, updateTime) values(?,?,?,?)";
        return update(sql, store.getOwnerId(), store.getName(), store.getDescription(), store.getUpdateTime());
    }

    @Override
    public Integer deleteStore(int id) {
        String sql = "delete from t_store where id=?";
        return update(sql, id);
    }

    @Override
    public Integer updateStore(Store store) {
        String sql = "update t_store set ownerId=?, name=?, description=?, updateTime=? where id=? ";
        return update(sql, store.getOwnerId(), store.getName(), store.getDescription(), store.getUpdateTime(), store.getId());
    }

    @Override
    public List<Store> queryStoresByOwnerId(int ownerId) {
        String sql = "select * from t_store where ownerId=? ";
        return queryForList(Store.class, sql, ownerId);
    }

    @Override
    public Store queryStoreById(int storeId) {
        String sql = "select * from t_store where id = ?";
        return queryForOne( Store.class,sql, storeId);
    }
}